import request from '@/utils/request'
import { API_CONFIG } from '@/api/config'

/**
 * 根据商品ID获取评价列表
 * @param {number} productId 商品ID
 * @returns {Promise}
 */
export function getCommentsByProductId(productId) {
  return request({
    url: `/fun/comment/product/${productId}`,
    method: 'get',
    params: {
      orgId: API_CONFIG.ORG_ID
    }
  })
}

// 获取商品评价列表
export function getCommentList(query) {
  const params = {
    ...query,
    orgId: API_CONFIG.ORG_ID
  }
  return request({
    url: '/mobile/product/comment/list',
    method: 'get',
    params: params
  })
}

// 获取商品评价详细信息
export function getComment(commentId) {
  return request({
    url: '/fun/comment/' + commentId,
    method: 'get',
    params: {
      orgId: API_CONFIG.ORG_ID
    }
  })
}

// 新增商品评价
export function addComment(data) {
  const requestData = {
    ...data,
    orgId: API_CONFIG.ORG_ID
  }
  return request({
    url: '/fun/comment',
    method: 'post',
    data: requestData
  })
}

// 修改商品评价
export function updateComment(data) {
  const requestData = {
    ...data,
    orgId: API_CONFIG.ORG_ID
  }
  return request({
    url: '/fun/comment',
    method: 'put',
    data: requestData
  })
}

// 删除商品评价
export function delComment(commentId) {
  return request({
    url: '/fun/comment/' + commentId,
    method: 'delete',
    params: {
      orgId: API_CONFIG.ORG_ID
    }
  })
}

// 获取评价详情（用于评论详情页面）
export function getCommentDetail(params) {
  const requestParams = {
    ...params,
    orgId: API_CONFIG.ORG_ID
  }
  return request({
    url: '/fun/comment/detail',
    method: 'get',
    params: requestParams
  })
}

// 商户回复评价
export function replyComment(data) {
  const requestData = {
    ...data,
    orgId: API_CONFIG.ORG_ID
  }
  return request({
    url: '/fun/comment/reply',
    method: 'post',
    data: requestData
  })
}

// 获取评价统计
export function getCommentStats(productId) {
  return request({
    url: `/fun/comment/stats/${productId}`,
    method: 'get',
    params: {
      orgId: API_CONFIG.ORG_ID
    }
  })
}